AutoEstPrice = function(A) {
	if (A)
		this.initConfig(A);
}
AutoEstPrice.prototype = {
	ssign : "",
	spec : "",
	plate : "",
	factory : 0,
	date1 : new Date(),
	scheme : 0,
	type : "",
	price:0,
	setConfig : function(A) {

		if (A.ssign)
			this.ssign = A.ssign;
		if (A.spec)
			this.spec = A.spec;
		if (A.plate)
			this.plate = A.plate;
		if (A.factory)
			this.factory = A.factory;
		if (A.date1)
			this.date1 = A.date1;
		if (A.scheme || A.processScheme)
			this.scheme = A.scheme ? A.scheme : A.processScheme;
		if (A.type || A.specType)
			this.type = A.type ? A.type : A.specType;
		if (A.name) {
			//this.name = A.name;
			//this.func = A.func;
			this[A.name] = A.func;

		}
		logger.debug("setConfig sucessful");
	},
	initConfig : function(A) {
		this.setConfig(A);

	},
	getProduct : function() {
		if(!this.product)
			this.product={};
		this.product["ssign"]=this.ssign;
		this.product["spec"]=this.spec;
		this.product["plate"]=this.plate;
		this.product["factory"]=this.factory;
		this.product["specType"]=this.type;
		this.product["scheme"]=this.scheme;
		logger.debug("---------------product is:"+this.ssign+","+this.spec+","+this.plate+","+this.factory+","+this.type+","+this.scheme);
		return this.product;
	},
	getDate : function() {
		return this.date1;
	},
	run : function() {
		if (arguments.length < 2)
			return;
		var arr = $A(arguments);
		var name = arr.shift();
		this[name].apply(this, arr);
	},
	getGrid : function() {
		return this.grid;
	},
	parseGrid : function(A,B) {

		if (A.length < 1)
			return null;
		if (!this.store)
			this.store = this.parseStore(A);
		else
			this.reloadData(A);
		if (!this.cm) {
			this.cm = this.parseColumn(A[0],B);

			this.grid = new Ext.grid.GridPanel({
						autoScoll : true,
						ds : this.store,
						width : 720,
						height : 260,
						cm : this.cm,
						viewConfig : {
							forceFit : false
						}
					});
		}
		return this.grid;
	},
	parseColumn : function(A,C) {
		if (!A.entryList)
			return null;
		var B = [];
		var C = A.entryList;
		for (var i = 0; i < C.length; i++) {
			B[i] = {
				header : this.translate(C[i].name),
				width : 60,
				sortable : true,
				renderTo:function(value)
				{
					return value;
				},
				dataIndex : C[i].name
			};
		}
		return new Ext.grid.ColumnModel(B);
	},
	parseStore : function(A) {
		var C = [];
		var D = [];
		for (var i = 0; i < A.length; i++) {
			var B = A[i].entryList;
			var E = [];
			if (i == 0) {
				for (var j = 0; j < B.length; j++)
					C[j] = B[j].name;
			}

			for (var j = 0; j < B.length; j++)
				E[j] = B[j].value;
			D[i] = E;
		}
		
		return new Ext.data.SimpleStore({
					fields : C,
					data : D
				});
	},
	getPrice:function(){
		var sum=this.store.sum("product_cost_last");
		return (sum/this.store.getCount()).toFixed(4);
	},
	reloadData : function(A) {
		logger.debug("start to reloadData");
		var D = [];
		logger.debug("A.length:"+A.length);
		for (var i = 0; i < A.length; i++) {
			var B = A[i].entryList;
			var E = [];
			for (var j = 0; j < B.length; j++)
				E[j] = B[j].value;
			D[i] = E;
		}
		this.store.loadData(D);
	},
	translate:function(A)
	{
		if(!this.dictionary)
			this.dictionary=this.readMap();
		var ret=this.dictionary[A]
		if(!ret)
			return this.translateProcessName(A);
		else
			return ret;
	},
	translateProcessName:function(A)
	{
		var arr=A.split("_");
		var print=A;
		if(arr.length>1)
		{
			var ret=this.dictionary[arr[1]];
			if(ret)
				print=arr[0]+ret;
		}
		return print;
	},
	readMap:function()
	{
		var obj={};
		obj.id="编号";
		obj.spec="规格";
		obj.factory="分厂号";
		obj.transnum="订单号";
		obj.ordernum="订单数量";
		obj.ssign="产品牌号";
		obj.ssign_yz="入库牌号";
		obj.spec_yz="入库规格";
		obj.peifang="配方价格";
		obj.grossweight="毛重";
		obj.qiandao_yield="前道收得率";
		obj.yimo="已磨成品率";
		obj.weimo="未磨成品率";
		obj.feipin="废品率";
		obj.qiandao_cost="前道费用";
		obj.product_cost_before="产品入库费用";
		obj.specType="规格类型";
		obj.processScheme="加工类型";
		obj.plate="镀层";
		obj.houdao_yield="后道收得率";
		obj.date1="日期";
		obj.ordercost="订单成本";
		obj.lirun="利润";
		obj.bz="备注";
		obj.maker="制表人";
		obj.makeDate="制表日期";
		obj.type="订单类型";
		obj.month1="月份";
		obj.year1="年份";
		obj.product_cost_last="产品估算成本";
		obj.baozhuangfei="包装费";
		obj.yield="成品率";
		obj.fee="加工费";
		obj.name="名称";
		return obj;
	}
}

function $A(A) {
	var arr = [];
	for (var i = 0; i < A.length; i++) {
		arr[i] = A[i];
	}
	return arr;
}
